// QRCodeDecoder.h
#ifndef QRCODEDECODER_H
#define QRCODEDECODER_H

#include "QRCodeCommon.h"
#include <opencv2/opencv.hpp>
#include <fstream>
#include <vector>

namespace QRCodeDecoder {
    using namespace QRCodeCommon;

    struct DecodeResult {
        uint16_t frameId;
        std::vector<uint8_t> payload;
        bool isStart;
        bool isEnd;
        bool isValid;
    };

    cv::Vec3b GetCellColor(const cv::Mat& frame, int gridRow, int gridCol);
    uint32_t BitsToInt(const std::vector<bool>& bits, int bitCount);
    std::vector<uint8_t> BitsToBytes(const std::vector<bool>& bits);
	std::vector<bool> ReadAllowedCells(const cv::Mat& frame, Mat& debugVisualization, Mat& produceFrame, vector<bool>& bits);
	void FillCell(cv::Mat& frame, int gridRow, int gridCol, const cv::Vec3b& color);
	void rgb2hsv(const cv::Vec3b& color, double& H, double& S, double& V);
	std::pair<uint16_t, std::vector<uint8_t>> DecodeQRFrame(const cv::Mat& frame, bool& isStart, bool& isEnd, const string& filename);
    void DecodeFile(const std::string& inputDir, const std::string& outputPath);
}

#endif